﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace Monopoly
{
    public partial class Card : Form
    {
        private int iKans;
        private int iAlgemeenFonds;
        private List<string> lstKans;
        private List<string> lstAlgemeenFonds;

        internal enum CardType
        {
            kans = 0,
            algemeenFonds = 1
        }


        public Card()
        {
            InitializeComponent();
            loadCards();
            Random random = new Random();
            // start random in the list
            iKans = random.Next(1, lstKans.Count());
            iAlgemeenFonds = random.Next(1, lstAlgemeenFonds.Count());
            this.Hide();
        }

        private void loadCards()
        {
            lstKans = new List<string>();
            lstAlgemeenFonds = new List<string>();

            // load kans cards
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(Properties.Resources.kansXML);
            XmlNode cardsNode = doc.FirstChild;

            foreach (XmlNode cardNode in cardsNode.ChildNodes)
            {
                lstKans.Add(cardNode["text"].InnerText);
            }

            // load algemeenFonds cards
            doc.LoadXml(Properties.Resources.algemeenFondsXML);
            cardsNode = doc.FirstChild;

            foreach (XmlNode cardNode in cardsNode.ChildNodes)
            {
                lstAlgemeenFonds.Add(cardNode["text"].InnerText);
            }
        }

        internal bool show(CardType type)
        {
            if (type == CardType.kans)
            {
                this.BackColor = Color.LightCyan;
                lblCardType.Text = "Kans";
                if (iKans + 1 == lstKans.Count)
                    iKans = 0;
                lblText.Text = lstKans[iKans++];
            }
            else
            {
                this.BackColor = Color.PeachPuff;
                lblCardType.Text = "Algemeenfonds";
                if (iAlgemeenFonds + 1 == lstAlgemeenFonds.Count)
                    iAlgemeenFonds = 0;
                lblText.Text = lstAlgemeenFonds[iAlgemeenFonds++];
            }
            this.Show();
            return false;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
    }
}
